define(["jquery"], function () {
    'use strict'
    let iptPhoneNum = $("#ipt-phonenum");
    let iptPwd = $("#ipt-pwd");
    let btnRegister = $("#btn-submit");
    let chkReadProtacal = $("#chk-readProtacal");
    let isAvoidLogin = chkReadProtacal.attr("checked");
    let avoidLoginStr = 0;
    function init() {
        btnRegister.on("click", login);
        chkReadProtacal.on("click", avoidLogin);
    }
    //验证是否阅免登陆
    function avoidLogin(evt) {
        let e = evt || window.event;
        isAvoidLogin = e.target.checked;
        if (isAvoidLogin) {
            // chkReadProtacal.css({
            //     background: "#ffe300",
            // })
            avoidLoginStr = 1;
        } else {
            avoidLoginStr = 0;
        }
    }
    function login() {
        var url = "http://zhaoyx0907.com/users/login.do";
        $.ajax(
            {
                url: url,
                data: {
                    username: $(iptPhoneNum).val(),
                    password: $(iptPwd).val(),
                },
                type: "get"
            }
        ).then(function (res) {
            console.log(res)
            if (res == 1) {
                alert("登陆失败，用户不存在或者密码不正确！！！");
            } else {
                alert("登陆成功！！！");
                jump(res);
            }

        }, function (error) {
            alert("登陆失败");
            console.log(error)
        })
    }
    function saveCookie(username) {
        var exp = new Date();
        exp.setTime(exp.getTime() + 1000 * 60 * 60 * 24 * 14);
        // console.log(avoidLoginStr)
        var str = "jp_user=" + username;
        str = avoidLoginStr == 1 ? str + ";expires=" + exp : str;
        document.cookie = str;
    }
    function jump(res) {
        saveCookie(res.username);
        location.href = "./index.html";
    }
    init();
})